# !/usr/bin/python
# coding: UTF-8

from django.shortcuts import render

import random

player_settings = {
        7: {'狼人': 2, '平民': 2, '预言家': 1, '猎人': 1, '女巫': 1},
        8: {'狼人': 3, '平民': 2, '预言家': 1, '猎人': 1, '女巫': 1},
        9: {'狼人': 3, '平民': 3, '预言家': 1, '猎人': 1, '女巫': 1},
        10: {'狼人': 3, '平民': 3, '预言家': 1, '猎人': 1, '女巫': 1, '守卫': 1},
        11: {'狼人': 4, '平民': 3, '预言家': 1, '猎人': 1, '女巫': 1, '守卫': 1},
        12: {'狼人': 4, '平民': 4, '预言家': 1, '猎人': 1, '女巫': 1, '守卫': 1},
        }

Rome_info = []


def home(request):
    ctx = {}
    if request.POST:
        player_num = int(request.POST['q'])
        player_setting = player_settings[player_num]
        player_list = []
        for role in player_setting:
            for i in range(player_setting[role]):
                player_list.append({'role': role,
                                    'player': 'not in',
                                    'person_id': ''})
        random.shuffle(player_list)
        room_num = str((random.randint(1, 1000)))
        ctx['rlt'] = room_num
        while True:
            if room_num not in Rome_info:
                break
        Rome_info[room_num] = {
            'player': player_list,
            'judge': '房主'
        }

    return render(request, 'home.html', ctx)



